#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "LinkedList.h"
#include "HigherOrderFunctions.h"
#include "Pair.h"

void print_int_test(void* element)
{
  int* x = (int *)element; 
  printf("%d",*x);
}

void print_double_test(void* element)
{
  double* x = (double *)element; 
  printf("%f",*x);
}

void print_pair_int_test(void* pair)
{
  struct Pair* arg = (struct Pair*)pair;
  printf("(%d,%d)", *(int*)(arg ->fst), *(int*)(arg ->snd));
}

void* test_map(void* x)
{
  int* arg = (int*)x;
  double* res = (double *)malloc(sizeof(double)); 
  *res = *arg * 3.5;
  return (void*)res;
}

int test_predicate(void* x)
{
  int* arg = (int*)x;
  return *arg > 90;
}

int main()
{
  int i;
  int r_test;
  struct LinkedList* test_list1 = (struct LinkedList*)malloc(sizeof(struct LinkedList));
  struct LinkedList* test_list2 = (struct LinkedList*)malloc(sizeof(struct LinkedList));
  struct LinkedList* test_zip;
  test_list1 ->head = 0;
  test_list2 ->head = 0;
  srand(time(0));
  for (i = 0; i < 10; i++)
  {
    int* r = (int*)malloc(sizeof(int));
    *r = rand() % 100 + 1;
    Add(test_list1,r);
    printf("Generated number: %d\n",*r);
  }
  for (i = 0; i < 8; i++)
  {
    int* r = (int*)malloc(sizeof(int));
    *r = rand() % 100 + 1;
    Add(test_list2,r);
    printf("Generated number: %d\n",*r);
  }
  PrintList(test_list1, &print_int_test);
  PrintList(test_list2, &print_int_test);
  test_zip = Zip(test_list1, test_list2);
  PrintList(test_zip, &print_pair_int_test);
  return 0;
}